package de.fuberlin.inf.alp3.ue09;

import java.util.HashSet;
import java.util.Set;

public class Graph implements Node {
    public String name;
    private final Set<Node> neighbours = new HashSet<Node>();
    public boolean visited = false;

    public Graph(String name) {
        this.name = name;
    }
    
    @Override
    public void add(Node neighbour) {
        this.neighbours.add(neighbour);
        ((Graph) neighbour).neighbours.add(this);
    }

    @Override
    public boolean iterate(Action a) {
        for (Node n : neighbours)
            if (a.act(n)) return true;
        return false;
    }

    @Override
    public void setVisited(boolean b) {
        this.visited = b;
    }

    @Override
    public boolean visited() {
        return this.visited;
    }

}